//
//  KLMyPublishCell.m
//  used
//
//  Created by xalo on 16/7/26.
//  Copyright © 2016年 王凯. All rights reserved.
//

#import "KLMyPublishCell.h"

@interface KLMyPublishCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong)NSArray *collectionArray;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UILabel *salePrice;
@property (weak, nonatomic) IBOutlet UILabel *originPrice;
@property (weak, nonatomic) IBOutlet UILabel *province;
@property (weak, nonatomic) IBOutlet UILabel *city;
@property (weak, nonatomic) IBOutlet UILabel *title;

@end

@implementation KLMyPublishCell


- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"CollectionViewCell_cell"];
    
    [self.collectionView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActoon)]];
    
    
}


- (void)tapActoon {
    
    if ([_delegate respondsToSelector:@selector(clickCollectionViewWithModel:)]) {
        [self.delegate clickCollectionViewWithModel:self.model];
    }
}





- (void)setModel:(KLGood *)model {
    
    _model = model;
 
    self.originPrice.text = model.originprice.description;
    self.salePrice.text = model.saleprice.description;
    self.province.text = model.province;
    self.city.text = model.city;
    self.collectionArray = model.imageurls;
    self.title.text = model.goodsname;

    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.collectionArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell_cell" forIndexPath:indexPath];
    
    //设置cell
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:self.collectionArray[indexPath.row]]];
    return cell;
}
@end
